/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.proyecto.datos;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;

/**
 *
 * @author mario
 */
public class EntityNota implements OperacionesDB {

    private int id_nota;
    private double lab1;
    private double discusion1;
    private double lab2;
    private double discusion2;
    private double lab3;
    private double discusion3;
    private double lab4;
    private double discusion4;
    int id_alumno;
    private String entCarnet;
    private String entNombre;
    private String entApellido;
    private String entCod_Materia;
    private double prom1;
    private double prom2;
    private double prom3;
    private double prom4;

    public EntityNota() {
    }

    public EntityNota(int id_nota, String entCarnet, String entNombre, String entApellido, String entCod_materia, double lab1, double discusion1, double lab2, double discusion2, double lab3, double discusion3, double lab4, double discusion4,double prom1,double prom2,double prom3,double prom4) {
        this.id_nota = id_nota;
        this.lab1 = lab1;
        this.discusion1 = discusion1;
        this.lab2 = lab2;
        this.discusion2 = discusion2;
        this.lab3 = lab3;
        this.discusion3 = discusion3;
        this.lab4 = lab4;
        this.discusion4 = discusion4;
        this.entCarnet = entCarnet;
        this.entNombre = entNombre;
        this.entApellido = entApellido;
        this.entCod_Materia = entCod_materia;
        this.prom1=prom1;
        this.prom2=prom2;
        this.prom3=prom3;
        this.prom4=prom4;
    }

    @Override
    public String EjecutarComando(String cadenaSQL) {
        Connection cn;
        Statement st;
        String msj;
        try {
            ConnDB db = new ConnDB();
            Class.forName(db.getDriver());
            cn = DriverManager.getConnection(db.getCadenaCon(), db.getUsuario(), db.getContrasenna());
            st = cn.createStatement();
            st.execute(cadenaSQL);
            st.close();
            cn.close();
            msj = "Comando ejecutado con exito";
        } catch (Exception ex) {
            msj = "El comando no pudo ser ejecutado";
            System.out.println(ex.toString());
        }
        return msj;
    }

    @Override
    public ArrayList EjecutarConsulta(String cadenaSQL) {

        ArrayList arry = new ArrayList();
        Connection cn;
        Statement st;
        ResultSet rs;

        try {

            ConnDB db = new ConnDB();
            Class.forName(db.getDriver());
            cn = DriverManager.getConnection(db.getCadenaCon(), db.getUsuario(), db.getContrasenna());
            st = cn.createStatement();
            rs = st.executeQuery(cadenaSQL);
            rs.beforeFirst();

            while (rs.next()) {

                arry.add(new EntityNota(rs.getInt("nota.id_nota"), rs.getString("al.carnet"), rs.getString("al.nombre"), rs.getString("al.apellido"), rs.getString("mate.cod_asignatura"), rs.getDouble("nota.lab1"), rs.getDouble("nota.discusion1"), rs.getDouble("nota.lab2"), rs.getDouble("nota.discusion2"), rs.getDouble("nota.lab3"), rs.getDouble("nota.discusion3"), rs.getDouble("nota.lab4"), rs.getDouble("nota.discusion4"),rs.getDouble("nota.prom1"),rs.getDouble("nota.prom2"),rs.getDouble("nota.prom3"),rs.getDouble("nota.prom4")));

            }
            rs.close();
            st.close();
            cn.close();
            db = null;


        } catch (Exception ex) {
            arry = null;
            System.out.println(ex.toString());
        }


        return arry;

    }

    public String getEntCarnet() {
        return entCarnet;
    }

    public void setEntCarnet(String entCarnet) {
        this.entCarnet = entCarnet;
    }

    public String getEntNombre() {
        return entNombre;
    }

    public void setEntNombre(String entNombre) {
        this.entNombre = entNombre;
    }

    public String getEntApellido() {
        return entApellido;
    }

    public void setEntApellido(String entApellido) {
        this.entApellido = entApellido;
    }

    public int getId_nota() {
        return id_nota;
    }

    public void setId_nota(int id_nota) {
        this.id_nota = id_nota;
    }

    public double getLab1() {
        return lab1;
    }

    public void setLab1(double lab1) {
        this.lab1 = lab1;
    }

    public double getDiscusion1() {
        return discusion1;
    }

    public void setDiscusion1(double discusion1) {
        this.discusion1 = discusion1;
    }

    public double getLab2() {
        return lab2;
    }

    public void setLab2(double lab2) {
        this.lab2 = lab2;
    }

    public double getDiscusion2() {
        return discusion2;
    }

    public void setDiscusion2(double discusion2) {
        this.discusion2 = discusion2;
    }

    public double getLab3() {
        return lab3;
    }

    public void setLab3(double lab3) {
        this.lab3 = lab3;
    }

    public double getDiscusion3() {
        return discusion3;
    }

    public void setDiscusion3(double discusion3) {
        this.discusion3 = discusion3;
    }

    public double getLab4() {
        return lab4;
    }

    public void setLab4(double lab4) {
        this.lab4 = lab4;
    }

    public double getDiscusion4() {
        return discusion4;
    }

    public void setDiscusion4(double discusion4) {
        this.discusion4 = discusion4;
    }

    public String getEntCod_Materia() {
        return entCod_Materia;
    }

    public void setEntCod_Materia(String entCod_Materia) {
        this.entCod_Materia = entCod_Materia;
    }

    public double getProm1() {
        return prom1;
    }

    public void setProm1(double prom1) {
        this.prom1 = prom1;
    }

    public double getProm2() {
        return prom2;
    }

    public void setProm2(double prom2) {
        this.prom2 = prom2;
    }

    public double getProm3() {
        return prom3;
    }

    public void setProm3(double prom3) {
        this.prom3 = prom3;
    }

    public double getProm4() {
        return prom4;
    }

    public void setProm4(double prom4) {
        this.prom4 = prom4;
    }
}
